{% extends "catalog/base_generic.html" %}

{% block title %}{{ book.title }} - 图书详情{% endblock %}

{% block content %}
<div class="card">
    <div class="card-body">
        <div class="d-flex justify-content-between align-items-start mb-4">
            <div>
                <h1 class="card-title h2 mb-3">
                    <i class="fas fa-book me-2"></i>{{ book.title }}
                </h1>
                <p class="text-muted mb-3">
                    <i class="fas fa-user me-2"></i>作者：
                    <a href="{{ book.author.get_absolute_url }}" class="text-decoration-none">
                        {{ book.author }}
                    </a>
                </p>
            </div>
            {% if perms.catalog.can_mark_returned %}
            <div>
                <a href="{% url 'book-update' book.pk %}" class="btn btn-outline-secondary me-2">
                    <i class="fas fa-edit me-1"></i>编辑图书
                </a>
                <a href="{% url 'book-delete' book.pk %}" class="btn btn-outline-danger">
                    <i class="fas fa-trash me-1"></i>删除图书
                </a>
            </div>
            {% endif %}
        </div>

        <div class="row mb-4">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-body bg-light">
                        <h5 class="card-title">
                            <i class="fas fa-info-circle me-2"></i>图书简介
                        </h5>
                        <p class="card-text">{{ book.summary|linebreaks }}</p>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="card">
                    <div class="card-body">
                        <h5 class="card-title">
                            <i class="fas fa-tags me-2"></i>图书信息
                        </h5>
                        <ul class="list-unstyled mb-0">
                            <li class="mb-2">
                                <i class="fas fa-language me-2"></i>语言：{{ book.language }}
                            </li>
                            <li class="mb-2">
                                <i class="fas fa-hashtag me-2"></i>ISBN：{{ book.isbn }}
                            </li>
                            <li>
                                <i class="fas fa-bookmark me-2"></i>类型：
                                {% for genre in book.genre.all %}
                                <span class="badge bg-secondary me-1">{{ genre }}</span>
                                {% endfor %}
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>

        <h5 class="card-title mb-4">
            <i class="fas fa-copy me-2"></i>馆藏副本
        </h5>
        
        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>副本ID</th>
                        <th>版本信息</th>
                        <th>状态</th>
                        <th>借阅者</th>
                        <th>应还日期</th>
                        {% if perms.catalog.can_mark_returned %}
                        <th>操作</th>
                        {% endif %}
                    </tr>
                </thead>
                <tbody>
                    {% for copy in book.bookinstance_set.all %}
                    <tr>
                        <td>{{ copy.id }}</td>
                        <td>{{ copy.imprint }}</td>
                        <td>
                            {% if copy.status == 'a' %}
                            <span class="badge bg-success">可借阅</span>
                            {% elif copy.status == 'm' %}
                            <span class="badge bg-warning text-dark">维护中</span>
                            {% elif copy.status == 'o' %}
                            <span class="badge bg-danger">已借出</span>
                            {% elif copy.status == 'r' %}
                            <span class="badge bg-info">已预订</span>
                            {% endif %}
                        </td>
                        <td>
                            {% if copy.borrower %}
                            {{ copy.borrower }}
                            {% else %}
                            -
                            {% endif %}
                        </td>
                        <td>
                            {% if copy.due_back %}
                            {{ copy.due_back|date:"Y-m-d" }}
                            {% else %}
                            -
                            {% endif %}
                        </td>
                        {% if perms.catalog.can_mark_returned %}
                        <td>
                            {% if copy.status == 'o' %}
                            <a href="{% url 'renew-book-librarian' copy.id %}" class="btn btn-sm btn-outline-primary">
                                <i class="fas fa-redo me-1"></i>续借
                            </a>
                            {% endif %}
                        </td>
                        {% endif %}
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %} 